/***
This set of do-files produces the main figures and tables in the paper.

It also contains the code to:
- reproduce most of the figures and tables in the
  Online Appendix. We provide the code for figures or tables that cannot be
  externally reproduced in figstabs_internal.do
- calculate scalars used in the text of the paper


If you are running this file interactively, please run data_external.do to load
and process public data that is used throughout the code below.

***/

*-------------------------------------------------------------------------------
* Configuration
*-------------------------------------------------------------------------------

project figstabs, cd

project, uses(code/config_project.do) raw
include code/config_project.do

*-------------------------------------------------------------------------------
* Build
*-------------------------------------------------------------------------------

* Folder to store black-and-white main figures for QJE
cap mkdir "results"
cap mkdir "results/QJE_Figures_BlackAndWhite"

* Main Figures *****************************************************************

* Produce Figure 1a
project, do("code/figs/Spending/Spending - National Spending Changes by Income Quartile.do")

* Produce Figure 1b
project, do("code/figs/Spending/Spending - Stacked Bar of Composition of Spending Changes.do")

* Produce Figure 1c
project, do("code/figs/Spending/Spending - Spending Changes by Sector in COVID vs GFC.do")

* Produce Figure 2 and Appendix Figure 7
project, do("code/figs/COVID-19 Incidence/COVID-19 Incidence - Binscatter Mobility, COVID cases, Median Income.do")

* Produce Figure 3
project, do("code/figs/Small Business Revenue/Small Business Revenue - Change in Revenue by ZIP code characteristics.do")

* Produce Figure 4a and 4b
project, do("code/figs/Jobs/Jobs - Change in Job Postings vs. Rent (April 2020).do")

* Produce Figure 4c
project, do("code/figs/Employment/Employment - Change in Employment vs Rent (July 2020) - County.do")

* Produce Figure 5a
project, do("code/figs/Employment/Employment - Change in Employment Rates by Income Quartile.do")

* Produce Figure 5b
project, do("code/figs/Employment/Employment - Change in Employment by Income Quartile Reweighting.do")

* Produce Figure 6a
project, do("code/figs/Jobs/Jobs - Change in Job Postings vs. Rent (Dec 2021).do")

* Produce Figure 6b, 6d
project, do("code/figs/Employment/Employment - Rent gradient.do")

* Produce Figure 6c
project, do("code/figs/Jobs/Jobs - Rent gradient.do")

* Produce Figure 8, Appendix Table 6, and Appendix Figs 21, 24, and 25
** (needs to be run before the do file for Figure 7)
project, do("code/figs/Policy/Policy - Create Stimulus Datasets.do")
project, do("code/figs/Policy/Policy - Stimulus Bar Chart by Round and Income Quartile.do")

* Produce Figure 7
project, do("code/figs/Policy/Policy - Stimulus Scatterplots.do")

* Produce Figure 9a
project, do("code/figs/Employment/Employment - Change in Low-Income Employment vs Workplace Rent.do")

* Produce Figure 9B, 9c, and 9d
project, do("code/figs/Spending/Spending - Change in Consumer Spending vs Workplace Rent.do")
project, do("code/figs/Spending/Spending - Low-Income Spending in High WP Rent ZIPs.do")

* Produce Figure 10
project, do("code/figs/Education/Education - Educational Progress by Income Quartile.do")

* Appendix Figures *************************************************************

* Produce Appendix Figure 3
project, do("code/figs/Jobs/Jobs - Job Postings vs JOLTS.do")

* Produce Appendix Figure 4a
project, do("code/figs/Spending/Spending - Seasonal Fluctuations in Consumer Spending in MARTS.do")

* Produce Appendix Figure 4b
project, do("code/figs/Employment/Employment - Seasonal Fluctuations in Employment in CES Data.do")

* Produce Appendix Figure 5a
project, do("code/figs/Spending/Spending - Components of Change in GDP.do")

* Produce Appendix Figure 5b
project, do("code/figs/Spending/Spending - MRTS Benchmark - changes.do")

* Produce Appendix Figure 6a
project, do("code/figs/Spending/Spending - MRTS Benchmark.do")

* Produce Appendix Figure 8a and 8b
project, do("code/figs/Spending/Spending - Consumer Spending vs Business Revenue.do")

* Produce Appendix Figure 9a
project, do("code/figs/Small Business Revenue/Small Business Revenue - Evolution of Revenue at the National Level.do")

* Produce Appendix Figure 10a, 10b, 10c
project, do("code/figs/Small Business Revenue/Small Business Revenue - Execute Code for Maps.do")

* Produce Appendix Figure 11
project, do("code/figs/Small Business Revenue/Small Business Revenue - Change in Revenue vs Rent by ZIP, Appendix.do")

* Produce Appendix Figures 12b and 12c
project, do("code/figs/Small Business Revenue/Small Business Revenue - Change in Revenue vs County Covariates.do")

* Produce Appendix Figure 13
project, do("code/figs/Employment/Employment - Benchmarking Employment.do")

* Produce Appendix Figure 14b
project, do("code/figs/Employment/Employment - CES Benchmark.do")

* Produce Appendix Figure 14c
project, do("code/figs/Employment/Employment - QCEW Benchmark.do")

* Produce Appendix Figure 15
project, do("code/figs/Employment/Employment - ADP Benchmark.do")

* Produce Appendix Figure 16a
project, do("code/figs/Employment/Employment - Change in Employment vs Rent - Zip.do")

* Produce Appendix Figure 16b, 16c, 16d
project, do("code/figs/Employment/Employment - Execute Code for Maps.do")

* Produce Appendix Figure 17
project, do("code/figs/Employment/Employment - Construct Recession Data.do")
project, do("code/figs/Employment/Employment - Geography of Unemployment in COVID vs Great Recession.do")

* Produce Appendix Figure 18
project, do("code/figs/Employment/Employment - Change in Employment by Income Quartile and Consumer Spending, Retail.do")

* Produce Appendix Figure 19
project, do("code/figs/Employment/Employment - CPS Panel Benchmark - Quartile Version.do")

* Produce Appendix Figure 20a
project, do("code/figs/Employment/Employment - Change in Low-Income Employment by Citizenship.do")

* Produce Appendix Figure 20b
project, do("code/figs/Employment/Employment - In-Migration at the State Level vs Median Rent.do")

* Produce Appendix Figure 22
project, do("code/figs/Policy/Policy - Robustness Scatterplots.do")

* Produce Appendix Figure 23
project, do("code/figs/Policy/Policy - Variance in Spending 7-day Moving Average.do")

* Produce Appendix Figure 26a
project, do("code/figs/State Re-Openings/Colorado vs New Mexico Re-Opening Event Study.do")

* Produce Appendix Figure 26b, 26c & Appendix Table 10, 11
project, do("code/figs/State Re-Openings/Construct Re-Openings Dataset.do")
project, do("code/figs/State Re-Openings/Stacked Re-Opening Event Studies.do")

* Produce Appendix Figure 27
project, do("code/figs/Spending/Spending - Consumer Spending around State-Ordered Business Closures.do")

* Notes: Appendix Figure 7 is produced in COVID-19 Incidence - Binscatter Mobility, COVID cases, Median Income.do.
*        Appendix Figure 21, 24, and 25 are produced in Policy - Stimulus Bar Chart by Round and Income Quartile.do.
*        Appendix Figures 1, 2, 6b, 9b, 12a, 14a, 28 use confidential data (see figstabs_internal.do).

********************************************************************************
* Tables
********************************************************************************

* Produce Table 1
project, do("code/tabs/Association Between Rent and Changes in Business Revenue and Employment.do")

* Produce Table 2
project, do("code/tabs/Create dataset for Mechanisms Underlying the Persistent Reduction in Low-Wage Employment.do")
project, do("code/tabs/Mechanisms Underlying the Persistent Reduction in Low-Wage Employment.do")

* Produce Appendix Table 5
project, do("code/tabs/Consumer Spending on Debit and Credit Cards, by Income Quartile and Sector - Panel A.do")
project, do("code/tabs/Consumer Spending on Debit and Credit Cards, by Income Quartile and Sector - Panel B and C.do")

* Compile table worksheets produced by the pipeline into a single workbook
project, do("code/tabs/compile_tables.do")

* Notes: Appendix Tables 1, 2, 4, 9 are manually updated.
*        Appendix Tables 3, 7, 8, 12 use confidential data.
*        Appendix Table 6 is produced with Figure 8.
*        Appendix Table 10 is producd in State Re-Openings/Construct Re-Openings Dataset.do
*        Appendix Table 11 is produced in State Re-Openings/Stacked Re-Opening Event Studies.do.

* Scalars **********************************************************************

project, do("code/figs/Spending/Spending - National Spending Series by Income Quartile.do")
project, do("code/figs/Employment/Employment - Wage Growth by Rent.do")
project, do("code/figs/Employment/Employment - Tracker Employment vs QCEW Quarter on Quarter.do")
project, do("code/figs/Employment/Employment - Percent of Q1 Decline Explained by Wage Growth.do")
project, do("code/figs/Employment/Employment - Create UI Claims Numbers for Selected Counties.do")
project, do("code/figs/Employment/Employment - Self Employment and Population.do")
